export interface IForm {
  isshow: boolean,
  title: string,
}
export interface IAd {
  id: number;
  type: number | string;
  pictrue: string;
  detailId: number | string;
  createTime?: string;
}
export interface IDirtList {
  data: IDirt[]
}

export interface IDirt {
  id: number;
  parentCode: number;
  dirtKey: number;
  dirtValue: string;
}

export interface ILevel {
  id: number | undefined;
  discount: string;
  icon: string;
  conditions: string;
  name: number | string;
  state: number;

}


export interface IAdmin {
  id: number | undefined;
  account: string,
  level: string,
  pwd: string,
  repwd: string,
  realName: string,
  roles: number[],
  status: string,
  phone: string
}

export interface IRole {
  id: number | undefined;
  roleName: string,
  rules: string,
  status: string,
  menuList?: IRole[]
}

export interface ILogin {
  username: string;
  password: string;
  captcha: string;
}

export type IUser = Omit<User, 'setProps'>

export class User {
  id?: number | undefined;
  account = '';
  level = '';
  pwd = '';
  repwd = '';
  realName = '';
  roles = [];
  status = true;
  phone = '';

  constructor(props?: IUser) {
    props && this.setProps(props)
  }

  setProps(data: IUser) {
    (Object.keys(this) as Array<IUserProps>).forEach(key => {
      if (key === 'roleIdList') {
        this.roleIdList = data.roleIdList || []
      } else {
        // @ts-ignore
        this[key] = data[key]
      }
    })
  }
}

export type IUserProps = keyof Omit<User, 'setProps'>